package com.atbeijing.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark03_Oper_Transform {

    def main(args: Array[String]): Unit = {

        val conf = new SparkConf().setMaster("local[*]").setAppName("TransformOperator")
        val sc = new SparkContext(conf)

        // TODO 算子 - 转换
        // Spark中的分区号是从0开始
        val rdd : RDD[Int] = sc.makeRDD(List(1,2,3,4,5,6), 3)

        val rdd1 = rdd.mapPartitionsWithIndex(
            (index, iter) => {
                // 数据类型
                // iterator
                if ( index == 1 ) {
                    iter.map(_*4)
                } else {
                    Nil.iterator
                }

            }
        )

        rdd1.collect().foreach(println)


        sc.stop()

    }
}
